<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" width="600" top="100px" destroy-on-close
		@closed="$emit('closed')">

		<div class="u-text-center">
			<el-table ref="table" :data="listData" row-key="id" @selection-change="selectionChange" stripe
				:hideDo="true" :hidePagination="true" :border="true">
				<el-table-column label="设备名称" prop="name"></el-table-column>
				<el-table-column label="设备序列号" prop="sn"></el-table-column>
			</el-table>
		</div>
	</el-dialog>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				showAMap: false,
				mode: "add",
				titleMap: {
					add: '设备查看',
					edit: '编辑',
					show: '查看'
				},
				visible: false,
				isSaveing: false,
				listData: [{
					id: "410000198611212735",
					name: "录像机",
					sn: '2198061243WLLB003520'
				}]
			}
		},
		watch: {
			'form.address'(nVal) {
				if (!nVal) {
					this.showAMap = false
				} else {
					this.showAMap = true
				}
			}
		},
		mounted() {

		},
		methods: {
			comfirmBmap(mapData) {
				console.log(mapData)
				this.form.lng = mapData.lng
				this.form.lat = mapData.lat
			},
			//显示
			open(mode = 'add') {
				this.mode = mode;
				this.visible = true;
				return this
			},
			//表单提交方法
			async submit() {
				var valid = await this.$refs.dialogForm.validate().catch(() => {})
				if (!valid) {
					return false
				}
				this.isSaveing = true;
				var res = await this.$API.demo.post.post(this.form);
				this.isSaveing = false;
				if (res.code == 200) {
					if (this.mode == 'add') {
						this.form.id = res.data
					}
					this.$emit('success', this.form, this.mode)
					this.visible = false;
					this.$message.success("操作成功")
				} else {
					this.$alert(res.message, "提示", {
						type: 'error'
					})
				}
			},
			//表单注入数据
			setData() {//data
				// this.form.id = data.id
				// this.form.name = data.name
				// this.form.sex = data.sex
				// this.form.email = data.email
				// this.form.num = data.num
				// this.form.boolean = data.boolean

				//可以和上面一样单个注入，也可以像下面一样直接合并进去
				//Object.assign(this.form, data)
			}
		}
	}
</script>

<style>
</style>
